package root.electronclass.electronclass.common.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.SPUtils
import root.electronclass.electronclass.R
import root.electronclass.electronclass.mvp.base.BasePresenterInterface
import root.electronclass.electronclass.mvp.base.BaseView
import java.lang.reflect.ParameterizedType

/**
 *
 * @author Lokiy
 * @date 2023/1/8 11:12
 */
abstract class ViewBindingActivity<T : ViewBinding> : BaseActivity() {
    private val bindingClass by lazy { (this::class.java.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<*> }

    val binding by lazy {
        bindingClass.getMethod("inflate", LayoutInflater::class.java).invoke(null, layoutInflater) as T
    }
    private lateinit var contentLayout: LinearLayout
    private lateinit var titleLayout: ConstraintLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
        // 设置全屏，隐藏状态栏和导航栏
        window.decorView.systemUiVisibility =
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                    View.SYSTEM_UI_FLAG_FULLSCREEN or
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        window.statusBarColor = android.graphics.Color.TRANSPARENT
        setContentView(binding.root)
        setWindowBackGround()
        init()
    }

    abstract fun init()

    /**
     * 设置全局背景图片
     */
    fun setWindowBackGround() {
        val view: View = this.window.decorView
        val src = SPUtils.getInstance().getInt("bg-key", R.mipmap.bg2)
        view.setBackgroundResource(src)
    }


    object EmptyPresenter : BasePresenterInterface<BaseView> {
        override fun onError(errorMessage: String?) {
        }

        override fun subscribe() {
        }

        override fun unsubscribe() {
        }

        override fun setView(view: BaseView?) {
        }

    }

    override fun onDestroy() {
        super.onDestroy()
    }


}
